﻿@using NetPageCommon;
@model PageModel<Notice>;
@{
    ViewData["Title"] = "Index";

}

<div class="container">
    <main role="main" class="pb-12 text-left">
        <figure class="figure">
            <img src="/images/xiangrikui.jpg" style="width:100%; height:200px;" class="figure-img img-fluid rounded" alt="...">
            @* <figcaption class="figure-caption">分页列表Demo.</figcaption> *@
        </figure>

    </main>
</div>

<table class="table table-hover">
    <thead>
        <tr>

            <th scope="col">id</th>
            <th scope="col">标题</th>
            <th scope="col">内容</th>
            <th scope="col"> <a href="/Notice/Add" target="_blank" class="btn btn-outline-primary btn-sm">添加</a> 总记录数 @ViewBag.total </th>
        </tr>
    </thead>
    <tbody>
        @{
            List<Notice> notices = Model.list;
            foreach (var item in notices)
            {
                <tr>
                    <td>@item.Id</td>
                    <td>@item.title</td>
                    <td>@item.content</td>
                    <td> 
                        <a href="/Notice/Edit?id=@item.Id" class="btn btn-outline-primary btn-sm">编辑</a>
                        <input type="button" value="删除" class="btn btn-outline-primary btn-sm" onclick="btnDelete('@item.Id')" />
                    </td>
                </tr>
            }
        }
    </tbody>
    @* <tfoot>
        <tr>
            <td colspan="4" >

            </td>
        </tr>
    </tfoot> *@
</table>


@{
    PageModelSample page = new PageModelSample();
    page.total = Model.total;
    page.page = Model.page;
    page.size = Model.size;
    page.url = Model.url;
    @await Component.InvokeAsync("Pagination", new { page = page });
}


<script>

     async function btnDelete(id)
    {

        const data = new FormData();
        data.append("id",id)

        const response = await  fetch('/Notice/Delete',
        {
            method:'POST',
              // headers: {
              //    'Content-Type': 'application/json;charset=utf-8'
              //   },
                    body: data

          });

          const json = await response.json();

          console.log("json 的结果");
          console.log(json);
          if(json.status==200)
          {
              alert(json.message);
          }
          else
          {
              alert("删除失败");
          }
    }
</script>




